export function fetchData() {
  //
}

export function makeFilter(formData, sourceType) {
  console.log(sourceType);
  let filter = [];
  //duration
  if (formData.duration && formData.duration.length === 2) {
    if (sourceType === "inspect") {
      filter.push(
        {
          keys: ["begin"],
          operator: "<=",
          values: [[formData.duration[1] + " 23:59:59"]],
        },
        {
          keys: ["time"],
          operator: ">=",
          values: [[formData.duration[0] + " 00:00:00"]],
        }
      );
    }
    if (sourceType === "rectify") {
      filter.push(
        {
          keys: ["eventTime"],
          operator: "<=",
          values: [[formData.duration[1] + " 23:59:59"]],
        },
        {
          keys: ["eventTime"],
          operator: ">=",
          values: [[formData.duration[0] + " 00:00:00"]],
        }
      );
    }

  }
  //client
  if (formData.client.length > 0) {
    filter.push({
      keys: ["clientOffice", "clientGroup", "clientName"],
      operator: "=",
      values: formData.client,
    });
  }
  //user
  if (formData.user.length > 0) {
    filter.push({
      keys: ["userOffice", "userGroup", "userName"],
      operator: "=",
      values: formData.user,
    });
  }
  //category
  if (formData.category.length > 0) {
    filter.push({
      keys: ["category"],
      operator: "=",
      // values: [formData.category],
      values: strarr2arrarr(formData.category)
    });
  }
  //rank
  if (formData.rank.length > 0) {
    filter.push({
      keys: ["clientRank"],
      operator: "=",
      // values: [formData.rank],
      values: strarr2arrarr(formData.rank)
    });
  }
  //position
  if (formData.position.length > 0) {
    filter.push({
      keys: ["seat", "sector"],
      operator: "=",
      values: formData.position,
    });
  }
  //type
  if (formData.type.length > 0) {
    filter.push({
      keys: ["type"],
      operator: "=",
      // values: [formData.type],
      values: strarr2arrarr(formData.type)
    });
  }
  //status
  if (formData.status.length > 0) {
    filter.push({
      keys: ["status"],
      operator: "=",
      // values: [formData.status],
      values: strarr2arrarr(formData.status)
    });
  }
  console.log(filter);
  return filter;
}

function strarr2arrarr(strarr) {
  let arrarr = [];
  for (let i = 0; i < strarr.length; i++) {
    arrarr.push([strarr[i]]);
  }
  return arrarr;
}